/*
 * Project Name:hbm-fe-easyui
 * File Name:IndexController.java
 * Package Name:com.hginfo.hbm.fe.eu.web
 * Date:2016年12月2日上午10:09:45
 * Copyright (c) 2016, hongguaninfo.com All Rights Reserved.
 *
 */
package cn.uce.cc.rest.control;
import cn.uce.base.vo.IcsEmpVo;
import cn.uce.base.vo.IcsOrgVo;
import cn.uce.common.constants.CcConstants;
import cn.uce.common.omg.biz.IOmgEmpBiz;
import cn.uce.common.omg.biz.IOmgOrgBiz;
import cn.uce.common.omg.service.IcsCurrentUser;
import cn.uce.common.utils.BeanUtilsEx;
import cn.uce.sms.api.service.biz.ICsRpRecodesBiz;
import cn.uce.sms.api.service.biz.ICsSmNoticeBiz;
import cn.uce.sms.vo.CsSmNoticeVo;
import cn.uce.utils.StringUtil;
import cn.uce.web.common.base.BaseController;
import cn.uce.web.common.base.CurrentUser;
import cn.uce.web.common.util.WebUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * IndexController.
 * ClassName:IndexController <br/>
 * Date: 2016年12月2日 上午10:09:45 <br/>
 *
 * @author qiujingde
 * @since V1.0.0
 */
@Controller
@RequestMapping("/")
public class IndexController extends BaseController {
	
	private static final String X_UA_COMPATIBLE = "X-UA-Compatible";
	private static final String IE_EDGE = "IE=Edge";
	/**
     * 
     */
    private static final Logger LOG	 = LoggerFactory.getLogger(IndexController.class);

    @Resource
    private ICsSmNoticeBiz csSmNoticeBiz;
    
    @Resource
    private ICsRpRecodesBiz csRpRecodesBiz;


    @Resource
    private IOmgOrgBiz omgOrgBiz;

    @Resource
    private IOmgEmpBiz omgEmpBiz;
    /**
     * login.
     * @param response response
     * @param model model
     * @return page
     * @since V1.0.0
     */
    @RequestMapping(value = "/login")
    public String login(HttpServletResponse response, Model model) {
//        model.addAttribute("modulus", getDefaultPublicKeyModulus());
//        model.addAttribute("exponent", getDefaultPublicKeyExponent());
        
        //让IE浏览器使用最高文档模式(避免使用杂项模式) yinyanzhen
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
        return "login";
    }
    
    /**
     * 显示验证码图片。
     * @author licheng
     * @param request request
     * @param response response
     * @since V1.0.0
     */
    @RequestMapping(value = "/captchaImage")
    public void getKaptchaImage(HttpServletRequest request, HttpServletResponse response) {
//        captchaHelper.getKaptchaImage(request, response);
    }
    
    /**
     * 获取公钥。
     * @return publicKey
     * @since V1.0.0
     */
    @RequestMapping(value = "/getPublicKey")
    @ResponseBody
    public Map<String, String> login() {
        Map<String, String> map = new HashMap<>(CcConstants.HASH_MAP_LENGTH);
//        map.put("modulus", getDefaultPublicKeyModulus());
//        map.put("exponent", getDefaultPublicKeyExponent());
        return map;
    }

    /**
     * @Description: (getCurrentUser)
     * @return
     * @author XJ
     * @date 2017年7月28日 上午8:51:44
     */
    @RequestMapping(value="getIcsCurrentUser")
    @ResponseBody
    public IcsCurrentUser getCurrentUser() {
        CurrentUser currentUser = WebUtil.getCurrentUser();
        IcsCurrentUser icsCurrentUser = new IcsCurrentUser();
        BeanUtilsEx.copyProperties(icsCurrentUser,currentUser);
        if(currentUser != null && currentUser.getCmsBaseOrgCode() != null){
            //查询此组织（乾坤组织）的基本信息
            IcsOrgVo icsOrgVo = omgOrgBiz.getOrgInforByCmsBaseOrgCode(currentUser.getCmsBaseOrgCode());
            if (icsOrgVo != null){
                icsCurrentUser.setFinanceCenterCode(icsOrgVo.getFinanceCenterCode());
                icsCurrentUser.setFinanceCenterName(icsOrgVo.getFinanceCenterName());
            }
        }
        //005 投诉方电话
        if(currentUser != null && currentUser.getEmpCode() != null){
            IcsEmpVo icsEmpVo =omgEmpBiz.getEmpByCode(currentUser.getEmpCode());
            if(icsEmpVo!=null){
                String mobile =icsEmpVo.getMobile();
                icsCurrentUser.setMobile(mobile);
            }
        }
        return icsCurrentUser;
    };
    
    
    /**
     * index.
     * @param response response
     * @param model model
     * @return page
     * @since V1.0.0
     * @updator: zhaocan
     * @date ：2018-04-24
     * @descrption :修改系统首页
     */
    @RequestMapping(value = "/home")
    public String homepage(HttpServletResponse response, Model model,HttpServletRequest request) {
        CurrentUser currentUser = WebUtil.getCurrentUser();
        String homePageUrl = "/home_netWork.do";
        //String homePageUrl = "/home_callCenter.do";
        List<String> roleCodeList = currentUser.getRoleCodeList();
        if(roleCodeList != null && roleCodeList.size() > 0) {
            String roleCode = roleCodeList.get(0);
            //呼叫中心角色最优先级
            if (roleCodeList.contains(CcConstants.ROLE_CODE_CCCS) ||
                    roleCodeList.contains(CcConstants.ROLE_CODE_CCCSL)) {
                roleCode = roleCode.contains(CcConstants.ROLE_CODE_CCCSL) ? CcConstants.ROLE_CODE_CCCSL : CcConstants.ROLE_CODE_CCCS;
                homePageUrl = "/home_callCenter.do";
            }
        }
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
        return "redirect:"+homePageUrl;
    }

    /**
     * index.
     * @param response response
     * @param model model
     * @return page
     * @since V1.0.0
     * @author： zhaocan
     * @date ：2018-04-24
     * @descrption :呼叫中心首页
     */
    @RequestMapping(value = "/home_callCenter")
    public String homeCallCenter(HttpServletResponse response, Model model) {
        //让IE浏览器使用最高文档模式(避免使用杂项模式) yinyanzhen
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
//        List<CsSmNoticeVo> csSmNotices = csSmNoticeBiz.getNewCsSmNotice();
//        model.addAttribute("newNotices", csSmNotices);
        return "homepage/home_callCenter";
    }

    /**
     * index.
     * @param response response
     * @param model model
     * @return page
     * @since V1.0.0
     * @author： chenqinglong
     * @date ：2018-04-24
     * @descrption :来电弹屏
     */
    @RequestMapping(value = "/home_screenPopup/{ani}")
    public String homeScreenPopup(HttpServletRequest request, HttpServletResponse response,@PathVariable String ani, Model model) {
        //让IE浏览器使用最高文档模式(避免使用杂项模式)
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
//        List<CsSmNotice> csSmNoticeServices=csSmNoticeService.getNewCsSmNotice();
        //String phone = request.getParameter("ani");
         String phone =ani;
        if (StringUtil.isEmpty(phone) || "undefined".equals(phone)){
            phone = "";
        }
//        model.addAttribute("newNotices", csSmNoticeServices);
        model.addAttribute("phone",phone);
        return "homepage/home_screenPopup";
    }
    /**
     * index.
     * @param response response
     * @param model model
     * @return page
     * @since V1.0.0
     * @author： zhaocan
     * @date ：2018-07-10
     * @descrption :UI更换，来电弹屏重写
     */
    @RequestMapping(value = "/callScreenPopUp/{ani}/{orderNo}")
    public String callScreenPopUp(HttpServletRequest request, HttpServletResponse response,@PathVariable String ani,@PathVariable String orderNo,Model model) {
        //让IE浏览器使用最高文档模式(避免使用杂项模式)
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
        String phone =ani;
        if (StringUtil.isEmpty(phone) || "undefined".equals(phone)){
            phone = "";
        }
        if (StringUtil.isEmpty(orderNo) || "undefined".equals(orderNo)){
            orderNo = "";
        }
        model.addAttribute("phone",phone);
        //工单子类型-无运单信息。2018-07-25
        model.addAttribute("noWayBill", CcConstants.ORDER_CHILD_TYPE_COMPLAIN_NOWAYBILL);
        //工单子类型-下单寄件
        model.addAttribute("placeOrder", CcConstants.ORDER_CHIL_TYPE_PLACE_ORDER);
        //运单号
        model.addAttribute("waybillNo",orderNo);
        return "homepage/callScreenPopUp";
    }


    /**
     * index.
     * @param response response
     * @param model model
     * @return page
     * @since V1.0.0
     * @author： zhaocan
     * @date ：2018-07-10
     * @descrption :UI更换，来电弹屏重写
     */
    @RequestMapping(value = "/ccosCallScreenPopUp/{ani}/{orderNo}")
    public String ccosCallScreenPopUp(HttpServletRequest request, HttpServletResponse response,@PathVariable String ani,@PathVariable String orderNo, Model model) {
        //让IE浏览器使用最高文档模式(避免使用杂项模式)
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
        String phone =ani;
        if (StringUtil.isEmpty(phone) || "undefined".equals(phone)){
            phone = "";
        }
        if (StringUtil.isEmpty(orderNo) || "undefined".equals(orderNo)){
            orderNo = "";
        }
        model.addAttribute("phone",phone);
        //工单子类型-无运单信息。2018-07-25
        model.addAttribute("noWayBill", CcConstants.ORDER_CHILD_TYPE_COMPLAIN_NOWAYBILL);
        //工单子类型-下单寄件
        model.addAttribute("placeOrder", CcConstants.ORDER_CHIL_TYPE_PLACE_ORDER);
        //运单号
        model.addAttribute("waybillNo",orderNo);
        return "homepage/ccosCallScreenPopUp";
    }

    /**
     * 来电弹屏模拟页面跳转
     * @param request
     * @param response
     * chenqinglong
     * @return
     */
    @RequestMapping(value = "/callScreenPopUpMoni")
    public String callScreenPopUpMoni(HttpServletRequest request, HttpServletResponse response) {
        //让IE浏览器使用最高文档模式(避免使用杂项模式)
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
        return "homepage/callScreenPopUpMoni";
    }


    /**
     * 快运来电弹屏模拟
     * @param request
     * @param response
     * chenqinglong
     * @return
     */
    @RequestMapping(value = "/ccosCallScreenPopUpMoni")
    public String ccosCallScreenPopUpMoni(HttpServletRequest request, HttpServletResponse response) {
        //让IE浏览器使用最高文档模式(避免使用杂项模式)
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
        return "homepage/ccosCallScreenPopUpMoni";
    }

    /**
     * temp
     * @param response response
     * @param model model
     * @return page
     * @since V1.0.0
     * @author： zhaocan
     * @date ：2018-04-24
     * @descrption :客服服务工单列表；临时展示，后续删除
     */
    @RequestMapping(value = "/servOrder_show")
    public String servOrderShow(HttpServletResponse response, Model model) {
        //让IE浏览器使用最高文档模式(避免使用杂项模式)
    	
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
        return "homepage/servOrder_show";
    }

    /**
     * temp
     * @param response response
     * @param model model
     * @return page
     * @since V1.0.0
     * @author： zhaocan
     * @date ：2018-04-24
     * @descrption :客服服务工单详情；临时展示，后续删除
     */
    @RequestMapping(value = "/servOrder_detail")
    public String servOrderDetail(HttpServletResponse response, Model model) {
        //让IE浏览器使用最高文档模式(避免使用杂项模式)
        response.setHeader(X_UA_COMPATIBLE, IE_EDGE);
        return "homepage/servOrder_detail";
    }
    /**
     * 修改密码。
     * @param request request
     * @param response response
     * @param model model
     * @return page
     * @since V1.0.0
     */
    @RequestMapping(value = "/showChangePersonalPwd/{changeReason}")
    public String showModifyPwd(@PathVariable String changeReason, HttpServletRequest request, HttpServletResponse response,
                                Model model) {
        model.addAttribute("changeReason", changeReason);
        return "personal_changePwd";
    }
    
}
